package com.tools;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.login.R;

public class PerCenterItem extends RelativeLayout {
    private TextView leftText, rightText;
    private ImageView image, arrow;

    public PerCenterItem(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(getContext()).inflate(R.layout.per_center_item, this);
        TypedArray type = context.obtainStyledAttributes(attrs, R.styleable.PerCenterItem);
        image = findViewById(R.id.per_center_item_image);
        arrow = findViewById(R.id.per_center_item_arrow);
        leftText = findViewById(R.id.per_center_item_left);
        rightText = findViewById(R.id.per_center_item_right);

        boolean isRight = type.getBoolean(R.styleable.PerCenterItem_show_right_text, true);
        boolean isArrow = type.getBoolean(R.styleable.PerCenterItem_show_arrow, true);

        image.setBackground(type.getDrawable(R.styleable.PerCenterItem_left_icon));
        leftText.setText(type.getString(R.styleable.PerCenterItem_left_text));
        if (isRight){
            rightText.setText(type.getString(R.styleable.PerCenterItem_right_text));
        }else {
            rightText.setVisibility(INVISIBLE);
        }

        if (isArrow){
            arrow.setVisibility(VISIBLE);
        }else {
            arrow.setVisibility(INVISIBLE);
        }
    }

    public void setLeftText(String text){
        leftText.setText(text);
    }

    public void setRightText(String text){
        rightText.setText(text);
    }
}
